Assembly: C1.WPF.C1Schedule (in C1.WPF.C1Schedule.dll)
Syntax
C# |
---|
public class PropertyBridge<TPropType> : FrameworkElement |
Visual Basic (Declaration) |
---|
Public Class PropertyBridge(Of TPropType) _ Inherits FrameworkElement |
Type Parameters
- TPropType
- Defines a type of exposed dependency properties.
Remarks
PropertyBridge<(Of <(<'TPropType>)>)> exposes two dependency properties, Source and Target, and keeps these property values equal, that is when a value of one property is being changed then the other property is being set to the same value. This simple behavior allows you to use non-DependencyProperty properties along with WPF mechanisms that are designed to work with DependencyProperty-only properties.
The behavioral difference between the Source and Target properties lies in the fact that after an initialization of XAML tree where the PropertyBridge<(Of <(<'TPropType>)>)> element is included, the Target property value is initialized with the Source property value – in all other respects the behavior of these properties is equivalent.
Note that if you need to use PropertyBridge<(Of <(<'TPropType>)>)> as a standalone object in run-time, that is without including it in a XAML tree, you need to call its BeginInit and EndInit methods – only after this action PropertyBridge<(Of <(<'TPropType>)>)> will start property value synchronization.
The useful examples of the PropertyBridge<(Of <(<'TPropType>)>)> class usage are:
- Binding between two non-dependency properties. Assign the Source property with a TwoWay binding having one non-dependency property as a source, and the Target property with a TwoWay binding having another non-dependency property as a source. After this, the non-dependency properties will behave as bound ones. This only works well if classes exposing the mentioned non-dependency properties implement the INotifyPropertyChanged interface.
- Setting a non-dependency property value from within a Trigger. Assign the Source property with a TwoWay or OneWayToSource binding having one non-dependency property as a source, and by specifying a Trigger's Setter set a value to the Target property of PropertyBridge<(Of <(<'TPropType>)>)> – this value will be assigned to the non-dependency property which is bound to Source.
- Many-to-many binding. Assign the Source and Target with MultiBinding bindings – you will get the many-to-many binding.
- Assign value to a nested property. Set up the Target property with a TwoWay or OneWayToSource binding where Binding.Path references a nested property, then assign the Source property (directly or from within a Setter) with a value - as a result the nested property will be assigned to this value.
- Assign a property of an object that is not accessible directly. Similar to the way explained in the previous item, and using Binding.RelativeSource in a binding to the Target property, you may assign a property value of an element that can't be referenced directly in XAML, for example TemplatedParent or some parent element in visual tree.
The PropertyBridge<(Of <(<'TPropType>)>)> class is derived from the FrameworkElement class and, in order to work properly, should be placed somewhere in the visual tree among elements that it should communicate with. The derivation from the FrameworkElement class is intentional; it allows the PropertyBridge<(Of <(<'TPropType>)>)> to be part of a visual tree, which in turn provides bindings established on its properties with a correct context.
The Visibility property of the PropertyBridge<(Of <(<'TPropType>)>)> element is set to Collapsed by default, so this object will not appear on a screen and doesn't participate in layout measurement and arrangement processes, that is, it doesn't affect a visual representation of the visual tree where it placed in.
Inheritance Hierarchy
System.Windows.Threading..::..DispatcherObject
System.Windows..::..DependencyObject
System.Windows.Media..::..Visual
System.Windows..::..UIElement
System.Windows..::..FrameworkElement
C1.WPF.C1Schedule..::..PropertyBridge<(Of <(<'TPropType>)>)>
C1.WPF.C1Schedule..::..PropertyBridge